from forbiddenfruit import curse
import itertools
import inspect

class enumerable:
    @staticmethod
    def map(self, fn):
        return map(fn, self)

    @staticmethod
    def filter(self, fn):
        return filter(fn, self)

    @staticmethod
    def reduce(self, fn, initial=None):
        return reduce(fn, self, initial) if initial else reduce(fn, self)

    @staticmethod
    def take(self, number):
        return itertools.islice(self, number)

    @staticmethod
    def toList(self):
        return list(self)

    @staticmethod
    def flattenMap(self, fn):
        return itertools.chain.from_iterable(map(fn, self))



for name, func in inspect.getmembers(enumerable):
    if inspect.isfunction(func):
        curse(object, name, func)
